﻿using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace NiuX.EntityFrameworks;

public partial class EfCoreRepository<TDbContext, TEntity>
{
    public async Task ExecuteSqlRawAsync(string sql)
    {
        await DbContext.Database.ExecuteSqlRawAsync(sql);
    }

    public async Task ExecuteTransactionAsync(Func<Task> func)
    {
        using (var transaction = await DbContext.Database.BeginTransactionAsync())
        {
            await func();
            await transaction.CommitAsync();
        }
    }
}